
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.joda.time.format.FormatUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ls.task.support.schedule.ConsoleManager;  
  
/** 
 * 任务调度工厂类 
 * @author Joyce.Luo 
 * @date 2015-3-31 下午03:38:35 
 * @version V3.0 
 * @since Tomcat6.0,Jdk1.6 
 * @copyright Copyright (c) 2015 
 */  
public class QuartzJobFactory implements Job {  
    protected static transient Logger logger = LoggerFactory.getLogger(ConsoleManager.class);
	   
    @Override  
    public void execute(JobExecutionContext context) throws JobExecutionException {  
        QuartzJob scheduleJob = (QuartzJob)context.getMergedJobDataMap().get("backup_job");  
        logger.info("定时任务开始执行，任务名称[" + scheduleJob.getJobName() + "]");  
        Date previousFireTime = context.getPreviousFireTime();  
        if(null != previousFireTime){  
            logger.info("定时任务上次调度时间：" + DateFormatUtils.format(previousFireTime,"yyyy-MM-dd HH:mm:ss"));  
        }  
        logger.info("定时任务下次调度时间：" + DateFormatUtils.format(context.getNextFireTime(),"yyyy-MM-dd HH:mm:ss"));  
        // 执行业务逻辑  
    }  
}  